package com.amit.struts;

import java.io.File;
import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.upload.FormFile;

public class UploadAction extends Action {
	
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		DynaActionForm df=(DynaActionForm) form;
		
	
		FormFile resume=(FormFile) df.get("resume");
		
		String filePath="E:/";
		String fileName=resume.getFileName();
		File file=new File(filePath,fileName);
		
		FileOutputStream fos=new FileOutputStream(file);
		fos.write(resume.getFileData());
		fos.flush();
		fos.close();
		
		request.setAttribute("fileName", fileName);
		request.setAttribute("filePath", filePath);
		
		return mapping.findForward("success");
	}

}
